<template>
  <div class="app-container">
    <el-card class="card-form">
      <div class="organization-title">绩效配置</div>
      <el-form :model="queryParams" ref="queryForm" :inline="true">
         <el-form-item label="创建时间">
          <el-date-picker
            v-model="dateRange"
            size="small"
            style="width: 252px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="请选择..."
            end-placeholder="结束日期"
            @change="changeDate"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="状态" prop="preStatus">
          <el-select
            v-model="queryParams.preStatus"
            placeholder="请选择"
            clearable
            size="small"
            style="width: 252px"
          >
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="handleQuery"
            >查询</el-button
          >
          <el-button size="small" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="card-table">
      <el-row :gutter="10" class="mb20 mt5">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="small"
            @click="handleAdd"
            v-hasPermi="['performance:manage:add']"
            >配置绩效指标</el-button
          >
        </el-col>
      </el-row>
      <el-table v-loading="loading" :data="performanceList" border>
        <el-table-column label="序号" align="center" type="index" width="65" />
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
        >
        </el-table-column>
        <el-table-column
          label="绩效指标"
          align="center"
          prop="indicatorsName"
          :formatter="indicatorsNameFormatter"
          :show-overflow-tooltip="true"
          width="515"
        />
        <el-table-column 
          label="适用范围"
          align="center"
          prop="rangeApplication"
          :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{scope.row.rangeApplication == '0'?'未考评项目':'全部项目'}}</span>
          </template>
        </el-table-column>
         <el-table-column
          label="状态"
          align="center"
          prop="preStatus"
        >
          <template slot-scope="scope">
            <span
              class="icon-state icon-red"
              v-show="
                scope.row.preStatus === '2' ||
                scope.row.preStatus === '已停用'
              "
              ><span></span
            ></span>
            <span
              class="icon-state icon-green"
              v-show="
                scope.row.preStatus === '0' ||
                scope.row.preStatus === '使用中'
              "
              ><span></span
            ></span>
            <span
              class="icon-state icon-blue"
              v-show="
                scope.row.preStatus === '1' ||
                scope.row.preStatus === '未启用'
              "
              ><span></span
            ></span>
            <span style="margin-left: 10px">{{
              scope.row.preStatus === "0" ? "使用中" : scope.row.preStatus === "1" ?"未启用":"已停用"
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleStart(scope.row)"
              v-show="scope.row.preStatus =='1'"
              v-hasPermi="['performance:manage:startUser']"
              >启用</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="handleFinish(scope.row)"
              v-show="scope.row.preStatus =='0'"
              v-hasPermi="['performance:manage:stopUser']"
              >停用</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="handleView(scope.row)"
              v-show="scope.row.preStatus =='2' || scope.row.preStatus =='0'"
              >查看</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click="handleEdit(scope.row)"
              v-show="scope.row.preStatus =='1'"
              v-hasPermi="['performance:manage:edit']"
              >编辑</el-button
            >

            <el-button
              size="mini"
              type="text"
              @click="handleDelete(scope.row)"
              v-show="scope.row.preStatus !='0'"
              v-hasPermi="['performance:manage:del']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>

    <!-- 查看绩效指标-查看对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="openView"
      width="1067px"
      append-to-body
      custom-class="dialog-box"
    >
      <el-table v-loading="loading" :data="editPerDataList" border>
        <el-table-column label="序号" align="center" type="index" width="65" />
        <el-table-column
          label="绩效指标"
          align="center"
          prop="indicatorsName"
          :show-overflow-tooltip="true"
          width="245"
        />
        <el-table-column label="规则" align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{scope.row.rulesRowShow}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="权重"
          align="center"
          prop="indicatorsWeight"
          width="187"
        />
      </el-table>
      <div style="margin-top:15px;">适用范围：{{ insertPerformanceDto.rangeApplication==0?'未考评项目':'全部项目'}}</div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openView=false">取消</el-button>
        <el-button type="primary" @click="openView=false">保存</el-button>
      </div>
    </el-dialog>
    <!-- 配置绩效指标-编辑对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="openEdit"
      width="1067px"
      append-to-body
      custom-class="dialog-box"
    >
      <el-row :gutter="10" class="mb20 mt5">
        <el-col :span="1.5">
          <el-button type="primary" icon="el-icon-plus" size="small" @click="addPerRow"
            >增加一行</el-button
          >
        </el-col>
      </el-row>
      <el-table v-loading="loading" :data="editPerDataList" border>
        <el-table-column label="序号" align="center" type="index" width="65" />
        <el-table-column
          label="绩效指标"
          align="center"
          :show-overflow-tooltip="true"
          width="245"
        >
          <template slot-scope="scope">
            <span v-show="!scope.row.show">{{scope.row.indicatorsName}}</span>
            <el-select v-show="scope.row.show" v-model="scope.row.indicatorsName" placeholder="请选择" >
            <el-option
              v-for="item in perNameOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictLabel">
            </el-option>
          </el-select>
          </template>
        </el-table-column>
        <el-table-column
          label="规则"
          align="center"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            <div v-show="!scope.row.show" style="width:200px;height:100%">{{scope.row.rulesRowShow}}</div>
            <div v-show="scope.row.show" style="width:200px;height:100%" @click="handRules(scope.row)">{{scope.row.rulesRowShow?scope.row.rulesRowShow:'请选择'}}</div>

            <!-- 配置规则对话框 -->
            <el-dialog
              :title="title"
              :visible.sync="openRule"
              width="1067px"
              append-to-body
              custom-class="dialog-box"
            >
              <el-row :gutter="10" class="mb20 mt5">
                <el-col :span="1.5">
                  <el-button type="primary" icon="el-icon-plus" size="small" @click="addRulesRow"
                    >增加一行</el-button
                  >
                </el-col>
              </el-row>
              <el-table v-loading="loading" :data="performanceRules" border>
                <el-table-column label="序号" align="center" type="index" width="65" />
                <el-table-column
                  label="条件"
                  align="center"
                  :show-overflow-tooltip="true"
                  width="245"
                >
                  <template slot-scope="scopeRules">
                    <span v-show="!scopeRules.row.show">{{scopeRules.row.postRegulation}}</span>
                    <el-select @change="print()" v-show="scopeRules.row.show" v-model="scopeRules.row.postRegulation" placeholder="请选择" >
                    <el-option
                      v-for="item in conditionOptions"
                      :key="item.key"
                      :label="item.dictLabel"
                      :value="item.dictLabel">
                    </el-option>
                  </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  label="参数"
                  align="center"
                  :show-overflow-tooltip="true"
                >
                  <template slot-scope="scopeRules">
                    <span v-show="!scopeRules.row.show">{{scopeRules.row.value}}</span>
                    <el-input v-show="scopeRules.row.show" v-model="scopeRules.row.value" placeholder="请输入"></el-input>
                  </template>
                </el-table-column>
                <el-table-column
                  label="得分"
                  align="center"
                  width="187"
                >
                  <template slot-scope="scopeRules">
                    <span v-show="!scopeRules.row.show">{{scopeRules.row.score}}</span>
                    <el-select v-show="scopeRules.row.show" v-model="scopeRules.row.score" placeholder="请选择" >
                    <el-option
                      v-for="item in scoreOptions"
                      :key="item.dictValue"
                      :label="item.dictLabel"
                      :value="item.dictValue">
                    </el-option>
                  </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  align="center"
                  class-name="small-padding fixed-width"
                >
                  <template slot-scope="scopeRules">
                    <el-button
                      v-show="scopeRules.row.show"
                      size="mini"
                      type="text"
                      @click="handleSureRule(scopeRules.row)"
                      >确认</el-button
                    >
                    <el-button
                      v-show="!scopeRules.row.show"
                      size="mini"
                      type="text"
                      @click="handleRowEditRule(scopeRules.row)"
                      >编辑</el-button
                    >
                    <el-button
                      size="mini"
                      type="text"
                      @click.native.prevent="
                        deleteRow(scopeRules.$index, performanceRules)
                      "
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
              
              <div slot="footer" class="dialog-footer">
                <el-button @click="cancelRules">取消</el-button>
                <el-button type="primary" @click="savaRules(scope.row)">保存</el-button>
              </div>
            </el-dialog>
          </template>
        </el-table-column>
        <el-table-column
          label="权重"
          align="center"
          prop="indicatorsWeight"
          width="187"
        >
          <template slot-scope="scope">
            <span v-show="!scope.row.show">{{scope.row.indicatorsWeight}}</span>
            <el-select v-show="scope.row.show" v-model="scope.row.indicatorsWeight" placeholder="请选择" >
            <el-option
              v-for="item in weightOptions"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              v-show="scope.row.show"
              size="mini"
              type="text"
              @click="handleSure(scope.row)"
              >确认</el-button
            >
            <el-button
              v-show="!scope.row.show"
              size="mini"
              type="text"
              @click="handleRowEdit(scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="text"
              @click.native.prevent="
                deleteRow(scope.$index, editPerDataList)
              "
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="mt20">
        <span class="mr20">适用范围:</span>
        <el-radio-group v-model="insertPerformanceDto.rangeApplication">
          <el-radio label="0">未考评项目</el-radio>
          <el-radio label="1">全部项目</el-radio>
        </el-radio-group>
      </div>       
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelEdit">取消</el-button>
        <el-button type="primary" @click="submitPer">保存</el-button>
      </div>
    </el-dialog>
    
  </div>
</template>

<script>
import {
  listPerformance,
  getPerformance,
  delPerformance,
  startPerformance,
  stopPerformance,
  addPerformance,
  updatePerformance,
 
} from "@/api/system/performance";
// import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu";
// import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept";

export default {
  name: "Organization",
  data() {
    return {
      // 点击规则的index
      clickIndex: 0,
      // 遮罩层
      loading: true,
      // 是否显示弹出窗
      openView: false,
      openEdit: false,
      openRule: false,
      radio:"1",
      // 总条数
      total: 0,
      // 绩效指标保存数据
      insertPerformanceDto:{perIndicators:[],rangeApplication:''},
      // 绩效列表数据
      performanceList: [],
      // 配置绩效指标
      editPerDataList:[],
      // 配置规则数据
      performanceRules:[],
      // 弹出层标题
      title: "",
      // 日期范围
      dateRange: [],
      // 状态数据字典
      statusOptions: [
        { dictValue: "0", dictLabel: "使用中" },
        { dictValue: "1", dictLabel: "未启用" },
        { dictValue: "2", dictLabel: "已停用" },
      ],
      // 加一行
      options: [
        { dictValue: "0", dictLabel: "CPU利用率均值" },
      ],
      // 绩效指标名称字典查询
      perNameOptions:[],
      // 权重字典查询
      weightOptions:[
        { dictValue: "0.05", dictLabel: "5%" },
        { dictValue: "0.10", dictLabel: "10%" },
        { dictValue: "0.15", dictLabel: "15%" },
        { dictValue: "0.20", dictLabel: "20%" },
        { dictValue: "0.25", dictLabel: "25%" },
        { dictValue: "0.30", dictLabel: "30%" },
        { dictValue: "0.35", dictLabel: "35%" },
        { dictValue: "0.40", dictLabel: "40%" },
        { dictValue: "0.45", dictLabel: "45%" },
        { dictValue: "0.50", dictLabel: "50%" },
        { dictValue: "0.55", dictLabel: "55%" },
        { dictValue: "0.60", dictLabel: "60%" },
        { dictValue: "0.65", dictLabel: "65%" },
        { dictValue: "0.70", dictLabel: "70%" },
        { dictValue: "0.75", dictLabel: "75%" },
        { dictValue: "0.80", dictLabel: "80%" },
        { dictValue: "0.85", dictLabel: "85%" },
        { dictValue: "0.90", dictLabel: "90%" },
        { dictValue: "0.95", dictLabel: "95%" },
        { dictValue: "1.00", dictLabel: "100%" },
      ],
      // 条件字典查询
      conditionOptions:[
        { dictValue: "大于", dictLabel: "大于", key: `0` },
        { dictValue: "大于等于", dictLabel: "大于等于", key: '1'  },
        { dictValue: "等于", dictLabel: "等于", key: '2'  },
        { dictValue: "小于等于", dictLabel: "小于等于", key: '3'  },
        { dictValue: "小于", dictLabel: "小于", key: '4'  },
      ],
      // 得分字典查询
      scoreOptions:[
        { dictValue: "0", dictLabel: "0" },
        { dictValue: "1", dictLabel: "1" },
        { dictValue: "2", dictLabel: "2" },
        { dictValue: "3", dictLabel: "3" },
        { dictValue: "4", dictLabel: "4" },
        { dictValue: "5", dictLabel: "5" },
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createTime: undefined,
        indicatorsName: undefined,
        preStatus: undefined,
        indicatorsName: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        indicatorsName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" },
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" },
        ],
        indicatorsWeight: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getDicts("performance_indicators").then((response) => {
      this.perNameOptions = response.data;
    });
  },
  methods: {
    print() {
      this.conditionOptions.forEach((item) => {
        item.key = item.key + Math.random()
      })
      this.$forceUpdate()
    },
    // 绩效名称格式化
    indicatorsNameFormatter(row){
      let indicatorsName = row.indicatorsName
      if(indicatorsName){
        return indicatorsName.join('、')
      }
      return ""
    },
    // 规则格式化
    rulesFormatter(rulesRow){
      let str = ""
      let arr = []
      rulesRow.forEach(item=>{
        arr.push(item.postRegulation+item.value+'个 得'+item.score+'分')
      })
      str = arr.join('; ')
    },
     //日期处理
    changeDate(val){
      if(val){
        this.queryParams.starTime=val[0]+ ' 00:00:00'
        this.queryParams.endTime=val[1]+ ' 23:59:59'
        }     
    },
    /** 查询绩效列表 */
    getList() {
      this.loading = true;
      listPerformance(this.queryParams,this.dateRange).then(
        (response) => {
          this.performanceList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 表单重置
    reset() {
      this.form = {
        perId: undefined,
        indicatorsName: undefined,
        indicatorsName: undefined,
        indicatorsWeight: undefined,
        indicatorsDesc: 0,
        preStatus: "0",
        menuIds: [],
        deptIds: [],
        menuCheckStrictly: true,
        deptCheckStrictly: true,
        remark: undefined,
      };
      this.insertPerformanceDto.perId = undefined;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams.starTime=undefined
      this.queryParams.endTime=undefined
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.editPerDataList = [{indicatorsName:"",performanceRules:[],indicatorsWeight:"",rulesRowShow:"",show:true, index: 0}]
      this.insertPerformanceDto.indicatorsVos = []
      this.insertPerformanceDto.rangeApplication = ""
      this.title = "配置绩效指标-新增";
      this.openEdit = true;
    },
    // 新增一行绩效指标
    addPerRow(){
      this.editPerDataList.push({indicatorsName:"",performanceRules:[],indicatorsWeight:"",rulesRowShow:"",show:true})
      this.editPerDataList.forEach((item,index) => {
        item.index = index
      })
    },
    // 删除一行绩效指标
    deleteRow(index, rows) {
      rows.splice(index, 1);
      this.editPerDataList.forEach((item,index) => {
        item.index = index
      })
    },
    /** 修改按钮操作 */
    handleEdit(row) {
      // this.reset();
      const perId = row.perId;
      getPerformance(perId).then((response) => {
        if(response.code ==200){
          this.insertPerformanceDto=response.data
          this.editPerDataList=response.data.indicatorsVos
          this.editPerDataList.map((item,index) => {
            item.index = index;
            this.$set(item, "show", false);
            this.$set(item, "performanceRules", item.rules);
            this.$set(item, "rulesRowShow", '');
            let arrPush=[]
            item.performanceRules.map(item1=>{
              this.$set(item1, "show", false);
              arrPush.push(
                item1.regulation==0?'>'+item1.value+'个 得'+item1.score+'分'
                :item1.regulation==1?'>='+item1.value+'个 得'+item1.score+'分'
                :item1.regulation==2?'='+item1.value+'个 得'+item1.score+'分'
                :item1.regulation==3?'<='+item1.value+'个 得'+item1.score+'分'
                :'<'+item1.value+'个 得'+item1.score+'分') 
            })
            item.rulesRowShow = arrPush.join('; ')
          });
        }        
      });
      this.title = "配置绩效指标-编辑";
      this.openEdit = true;
    },
    // 显示规则弹窗按钮
    handRules(row){
      this.clickIndex = row.index
      this.title="配置绩效指标-规则"
      row.performanceRules.forEach((item,index) => {
        if (item.regulation == '0') {
          item.postRegulation = '大于'
        } else if (item.regulation == '1') {
          item.postRegulation = '大于等于'
        } else if (item.regulation == '2') {
          item.postRegulation = '等于'
        } else if (item.regulation == '3') {
          item.postRegulation = '小于等于'
        } else if (item.regulation == '4') {
          item.postRegulation = '大于'
        }
      })
      this.performanceRules = row.performanceRules
      this.openRule = true
    },
    /** 查看按钮操作*/
    handleView(row) {
      const perId = row.perId;
      getPerformance(perId).then((response) => {
        if(response.code ==200){
          this.insertPerformanceDto=response.data
          this.editPerDataList=response.data.indicatorsVos
          this.editPerDataList.map((item) => {
            this.$set(item, "performanceRules", item.rules);
            this.$set(item, "rulesRowShow", '');
            let arrPush=[]
            item.performanceRules.forEach(item=>{
              arrPush.push(
                item.postRegulation==0?'>'+item.value+'个 得'+item.score+'分'
                :item.postRegulation==1?'>='+item.value+'个 得'+item.score+'分'
                :item.postRegulation==2?'='+item.value+'个 得'+item.score+'分'
                :item.postRegulation==3?'<='+item.value+'个 得'+item.score+'分'
                :'<'+item.value+'个 得'+item.score+'分') 
            })
            item.rulesRowShow = arrPush.join('; ')
          });         
        }
      });
      this.title="配置绩效指标-查看"
      this.openView=true
    },
    cancelEdit(){
      this.openEdit = false;
    },
    // 保存绩效指标
    submitPer(){
      this.insertPerformanceDto.perIndicators = this.editPerDataList.filter(
        (item) => item.show == false
      );
      console.log(this.insertPerformanceDto)
      if (this.insertPerformanceDto.perIndicators.length == 0) {
        return this.$message.error("请先填写内容后保存");
      }
      for(let i = 0; i < this.insertPerformanceDto.perIndicators.length; i++) {
        if( this.insertPerformanceDto.perIndicators[i].indicatorsName == "" || this.insertPerformanceDto.perIndicators[i].indicatorsWeight == '' ||  this.insertPerformanceDto.rangeApplication == '') {
          return this.$message.error("请先填写内容后保存");
        }
      }
      let insertPerformanceDto = JSON.parse(JSON.stringify(this.insertPerformanceDto))
      // insertPerformanceDto.perIndicators.forEach((item) => {
      //   delete item.index
      //   delete item.indicatorsName
      // })
      if (!this.insertPerformanceDto.perId){
          addPerformance(insertPerformanceDto).then(response=>{
          if(response.code == 500){
            this.msgError('权重总值不等于100%');
          }else{
            this.msgSuccess("新增成功");
            this.getList();
            this.openEdit = false;
          }
          
        })
      } else {
        delete insertPerformanceDto.preStatus
        insertPerformanceDto.perName = ''
        insertPerformanceDto.indicatorsVos.forEach((item,index) => {
          delete item.rules
          delete item.rulesRowShow
          delete item.show
          delete item.indicatorsDesc
          delete item.indicatorsId
          delete item.perId
        })
        insertPerformanceDto.insertPerIndicatorsDtoS = insertPerformanceDto.indicatorsVos
        delete insertPerformanceDto.indicatorsVos
        delete insertPerformanceDto.perIndicators
        let perId = insertPerformanceDto.perId
        delete insertPerformanceDto.perId
        updatePerformance(perId,insertPerformanceDto).then((response) => {
          if(response.code == 500){
            this.msgError('权重总值不等于100%');
          }else{
            this.msgSuccess("修改成功");
            this.getList();
            this.openEdit = false;
          }
          
        });
      }
    },
    // 添加一行规则
    addRulesRow(){
      this.performanceRules.push({postRegulation:"",value:"",score:"", show:true, regulation:"", postRegulation: ""})
    },
    // 取消规则按钮
    cancelRules(){
      this.openRule=false
    },
    // 保存规则
    savaRules(row) {
      let arrPush=[]
      let arr = this.performanceRules.filter(item=>{
        return item.show == false
      });
      if (arr.length == 0) {
        return this.$message.error("请先确定填写的内容后保存");
      }
      for(let i = 0; i < arr.length; i++) {
        if( arr[i].postRegulation == "" || arr[i].value == '' ||  arr[i].score == '') {
          return this.$message.error("请先填写内容后保存");
        }
      }
      console.log(this.performanceRules)
      arr.forEach(item=>{
        arrPush.push(
          item.regulation=='0'?'>'+item.value+'个 得'+item.score+'分'
          :item.regulation=='1'?'>='+item.value+'个 得'+item.score+'分'
          :item.regulation=='2'?'='+item.value+'个 得'+item.score+'分'
          :item.regulation=='3'?'<='+item.value+'个 得'+item.score+'分'
          :'<'+item.value+'个 得'+item.score+'分') 
      })
      this.editPerDataList.forEach((item,index) => {
        if (index == this.clickIndex) {
          item.rulesRowShow = arrPush.join('; ')
          item.performanceRules = this.performanceRules.filter(item=>{
            return item.show == false
          });
        }
      })
      console.log(this.editPerDataList)
      this.openRule=false
    },
    // 新增规则确认按钮
    handleSureRule(row) {
      if (row.postRegulation == '') {
        return this.$message.error('请先选择条件')
      } else if (row.value == '') {
        return this.$message.error('请先输入参数')
      } else if (row.score == '') {
        return this.$message.error('请先选择得分')
      } 
      if (row.postRegulation == '大于') {
        row.regulation = '0'
      } else if (row.postRegulation == '大于等于') {
        row.regulation = '1'
      } else if (row.postRegulation == '等于') {
        row.regulation = '2'
      } else if (row.postRegulation == '小于等于') {
        row.regulation = '3'
      } else if (row.postRegulation == '大于') {
        row.regulation = '4'
      }
      row.show = false
    },
    // 确认按钮 绩效指标
    handleSure(row){
      if (row.indicatorsWeight == '' || row.rulesRowShow == '' || row.indicatorsName == '') {
        return this.$message.error('请先填写内容')
      }
      this.perNameOptions.forEach((item,index) =>{
        if (item.dictLabel == this.editPerDataList[row.index].indicatorsName) {
          this.editPerDataList[row.index].indicatorsName = item.dictLabel
        }
      })
      row.show = false
    },
    // 当前规则编辑按钮
    handleRowEditRule(row) {
      row.show = true
    },
    // 当前行编辑按钮
    handleRowEdit(row){
      row.show = true
    },
   
    /** 删除按钮操作 */
    handleDelete(row) {
      const perId = row.perId || this.ids;
      this.$confirm("是否确认删除 ？", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "del_box",
      })
        .then(function () {
          return delPerformance(perId);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 启用按钮操作 */
    handleStart(row) {
      const perId = row.perId;
      this.$confirm("是否确认启用 ？", "启用", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "del_box",
      })
        .then(function () {
          return startPerformance(perId);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("启用成功");
        });
    },
    /** 停用按钮操作 */
    handleFinish(row) {
      const perId = row.perId;
      this.$confirm("是否确认停用 ？", "停用", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "del_box",
      })
        .then(function () {
          return stopPerformance(perId);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("停用成功");
        });
    },
  },
};
</script>
<style scoped lang="scss">
.organization-title {
  font-size: 18px;
  font-family: PingFang SC, PingFang SC-Medium;
  font-weight: 500;
  margin-bottom: 24px;
  color: #000000;
}
.card-table {
  margin-top: 10px;
  .el-pagination {
    text-align: center;
    margin-top: 40px;
  }
}
 // 状态样式
  .icon-state {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 16px;
    position: relative;
    top: 3.5px;
    span {
      display: inline-block;
      margin: 5px;
      width: 7px;
      height: 7px;
      border-radius: 16px;
    }
  }
  .icon-red {
    background: rgba(223, 32, 66, 0.1);
    span {
      background: #df2042;
    }
  }
  .icon-green {
    background: rgba(51, 168, 61, 0.1);
    span {
      background: #33a83d;
    }
  }
  .icon-blue {
    background: rgba(49, 113, 238, 0.1);
    span {
      background: #3171ee;
    }
  }
</style>
<style lang="scss">
/**表单label取消加粗 */
.card-form {
  .el-card__body {
    padding-bottom: 0;
  }
  label {
    font-weight: normal !important;
  }
  .el-form--inline .el-form-item {
    margin-right: 60px;
  }
  .el-form--inline .el-form-item:last-child {
    margin-right: 0px;
  }
}
/* 弹出窗样式 */
.dialog-box {
  .el-dialog__body {
    padding: 24px 69px 24px 69px;
    border-top: 1px solid #ebecef;
    border-bottom: 1px solid #ebecef;
    label {
      font-weight: 400 !important;
    }
  }
  .el-dialog__footer {
    padding: 16px 20px;
  }
  .el-dialog__headerbtn {
    background: url("../../../assets/images/icon_dialog_close.png");
    background-size: 100%;
    width: 16px;
    height: 16px;
    .el-dialog__close {
      visibility: hidden;
    }
  }
}
/* el-descriptions-item 文字居中 */
.el-descriptions__body .el-descriptions__table .el-descriptions-item__cell {
  text-align: center;
}
/* 删除弹出框样式 */
.del_box {
  width: 345px;
  height: 175px;
  .el-message-box__headerbtn {
    background: url("../../../assets/images/icon_dialog_close.png");
    background-size: 100%;
    width: 16px;
    height: 16px;
    .el-message-box__close {
      visibility: hidden;
    }
  }
  .el-message-box__content {
    padding: 26px 95px;
    font-size: 16px;
    .el-message-box__status.el-icon-warning {
      color: #ea4747;
    }
    .el-message-box__status + .el-message-box__message {
      padding-right: 0;
    }
  }
}
// 分页居中
.card-table {
  .pagination-container {
    right: 30%;
  }
}
</style>
